package com.heima.controller;

import com.heima.minio.MinIoTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author itheima
 * @since 2022-12-31
 */
@RestController
public class TestController {

    @Autowired
    private MinIoTemplate minIo;

    @PostMapping("upload")
    public String upload(MultipartFile file) throws IOException {

        // 1. 接收图片内容

        // 2. 调用minio工具类上传
        String url = minIo.uploadFile("", Long.toString(System.currentTimeMillis()), file.getInputStream(), "png");

        // 3. 测试图片远程地址可不可以访问
        System.out.println(url);

        return url;
    }
}
